package com.yq.cp.service.data.impl;

import com.yq.cp.entity.data.NkData;
import com.yq.cp.entity.data.NkDataDetails;
import com.yq.cp.entity.data.vo.NkDataVo;
import com.yq.cp.mapper.data.NkDataDetailsMapper;
import com.yq.cp.mapper.data.NkDataMapper;
import com.yq.cp.service.data.NkDataService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class NkDataServiceImpl implements NkDataService {

    @Resource
    NkDataMapper nkDataMapper;
    @Resource
    NkDataDetailsMapper nkDataDetailsMapper;
    @Override
    public void add(List<NkDataVo> list) {
        for (int i = 0; i < list.size(); i++) {
            NkDataVo n = list.get(i);
            NkData nkData=new NkData();
            nkData.setDataId(n.getId());
            nkData.setSerialNo(n.getSerialNo());
            nkDataMapper.insert(nkData);
            List<NkDataDetails> NkDataDeatisls = n.getData();
            for (int j = 0; j < NkDataDeatisls.size(); j++) {
                NkDataDetails nkDataDetails = NkDataDeatisls.get(j);
                nkDataDetails.setNkDataId(nkData.getId());
                nkDataDetailsMapper.insert(nkDataDetails);
            }
        }

    }
}
